package jmine.tec.persist.schema.association.mappedby;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;

@Entity
@Table(name = "LIST_OWNER")
@Documentation("TABELA LIST OWNER")
@SequenceGenerator(name = "SEQ_LOWNER", sequenceName = "SEQ_LOWNER")
public class ListOwner extends PersistableBusinessObject {

    private Long id;

    private List<ListOwned> associations = new ArrayList<ListOwned>();

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator = "SEQ_LOWNER")
    @Column(name = "COD_OWNER", precision = 17, nullable = false)
    @Documentation("CODIGO OWNER")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the associations
     */
    @OneToMany(mappedBy = "owner")
    @Cascade(CascadeType.SAVE_UPDATE)
    public List<ListOwned> getAssociations() {
        return this.associations;
    }

    /**
     * @param associations the associations to set
     */
    public void setAssociations(List<ListOwned> associations) {
        this.associations = associations;
    }

    public void add(ListOwned listOwned) {
        listOwned.setOwner(this);
        this.associations.add(listOwned);
    }

}
